<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE HTML>
<html>
<head>
  <title>后台管理系统</title>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <link href="/resources/css/dpl-min.css" rel="stylesheet" type="text/css" />
  <link href="/resources/css/bui-min.css" rel="stylesheet" type="text/css" />
  <link href="/resources/css/page-min.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div class="container">

    <form id="searchForm" class="form-horizontal">
        <div class="row">
            <div class="control-group span8" style="width:250px;">
                <label class="control-label" style="width:80px;">昵称：</label>
                <div class="controls" style="width:150px;">
                    <input type="text" class="control-text" name="nickName">
                </div>
            </div>
            <div class="control-group span8"  style="width:250px;">
                <label class="control-label"  style="width:80px;">账号：</label>
                <div class="controls"  style="width:150px;">
                    <input type="text" class="control-text" name="account">
                </div>
            </div>
            <div class="control-group span8"  style="width:250px;">
                <label class="control-label"  style="width:80px;">姓名：</label>
                <div class="controls"  style="width:150px;">
                    <input type="text" class="control-text" name="userName">
                </div>
            </div>
            <div class="control-group span8">
                <label class="control-label">类型：</label>
                <div class="controls" >
                    <select name="type" id="type" >
                        <option value="">--全部--</option>
                        <option value="Gold">金牌代理</option>
                        <option value="General">全国总代</option>
                        <option value="Partner">区域合伙人</option>
                    </select>
                </div>
            </div>
            <div class="span3 offset2" style="width:80px;">
                <button  type="button" id="btnSearch" class="button button-primary">搜索</button>
            </div>
        </div>
    </form>

    <div class="search-grid-container">
        <div id="grid"></div>
    </div>
</div>
<script type="text/javascript" src="/resources/js/jquery-1.8.1.min.js"></script>
<script type="text/javascript" src="/resources/js/bui-min.js"></script>
<script type="text/javascript" src="/resources/js/config-min.js"></script>
<script type="text/javascript">
    var store,gridCfg;
  BUI.use(['common/search','common/page','bui/grid','bui/overlay','bui/form'],function (Search,Page,Grid,Overlay,Form) {
    var  columns = [
              {title:'名称',dataIndex:'cardName',width:120},
              {title:'账号',dataIndex:'account',width:80},
              {title:'用户类型',dataIndex:'type',width:100,renderer:function(value,obj){
                    if(obj.type=='Gold'){
                        return "金牌代理商";
                    }else if(obj.type=='General'){
                        if(obj.isPartner=='1'){
                            if(obj.userLevel=='0'){
                                return "省级合伙人";
                            }else if(obj.userLevel=='1'){
                                return "副省级合伙人";
                            }else if(obj.userLevel=="2"){
                                return "地市合伙人";
                            }else if(obj.userLevel=="3"){
                                return "区县合伙人";
                            }
                        }else{
                        return "全国总代";
                        }
                    }else if(obj.type=="Partner"){
                        return "区域合伙人";
                    }
                }},
                {title:'微信号',dataIndex:'nickName',width:120},
                {title:'状态',dataIndex:'status',width:80,renderer:function(value,obj){
                    if(obj.status=='NORMAL'){
                        return "正常";
                    }else if(obj.status=='FROZEN'){
                        return "冻结";
                    }else{
                        return "待审核";
                    }
                }},
                {title:'联系电话',dataIndex:'mobile',width:120},
                {title:'加入时间',dataIndex:'dateStr',width:120},
                {title:'推荐人账号',dataIndex:'recommendId',width:120},
                {title:'统计',dataIndex:'subSize',width:100,renderer:function(value,obj){
                    var editStr =  Search.createLink({ //链接使用 此方式
                        id : 'sub' + obj.id,
                        title : '查看下级',
                        text : '('+obj.subSize+")",
                        href : '/member/listTeam?level=0&id='+obj.id
                    });
                    return "下级："+editStr+"<br/>团队：<a href='javascript:void(0);' onclick=\"showCnt('"+obj.id+"')\">统计</a>";
                }},
                {title:'操作',dataIndex:'operate',width:150,renderer:function(value,obj){
                    var editStr =  Search.createLink({ //链接使用 此方式
                        id : 'edit' + obj.id,
                        title : '查看详情',
                        text : '查看',
                        href : '/member/beforeEdit?id='+obj.id
                    });
                    var str1 =  Search.createLink({ //链接使用 此方式
                        id : 'update' + obj.id,
                        title : '编辑',
                        text : '编辑',
                        href : '/user/beforeEdit?id='+obj.id
                    });

                    var updateStr = "";
                    if(obj.status=='NORMAL'){
                        updateStr = "<a href=\"javascript:void(0);\" onclick=\"updateStatus('"+obj.id+"','FROZEN')\">冻结</a>&nbsp;&nbsp;";
                    }else{
                        updateStr = "<a href=\"javascript:void(0);\" onclick=\"updateStatus('"+obj.id+"','NORMAL')\">启用</a>&nbsp;&nbsp;";
                    }
                    var xqstr = "";
                    if((obj.type=='General'&&obj.isPartner=='1')||(obj.type=='Partner')){
                        xqstr = "<a href=\"javascript:void(0);\" onclick=\"xq('"+obj.id+"')\">区域合伙人续签</a>&nbsp;&nbsp;";
                    }
                    var nextstr =  Search.createLink({ //链接使用 此方式
                        id : 'team' + obj.id,
                        title : '查看'+obj.nickName+'团队业绩',
                        text : '团队业绩',
                        href : '/member/listTeamYj?id='+obj.id
                    });

                    return editStr+updateStr+xqstr+nextstr;
                }}
            ];
            store = Search.createStore('/member/listData');
            gridCfg = Search.createGridCfg(columns,{

              plugins : [BUI.Grid.Plugins.CheckSelection] // 插件形式引入多选表格
            });

  });
    function updateStatus(id,status){
        var msg = "确定冻结该数据吗？";
        if(status=='NORMAL'){
            msg = "确定启用该数据吗？";
        }
        BUI.Message.Confirm(msg,function(){
            $.ajax({
                url :"/member/updateStatus",
                type : 'post',
                data : {id:id,status:status},
                success : function(data){
                    if(data.success){ //删除成功
                        top.topManager.reloadPage();
                    }else{ //删除失败
                        BUI.Message.Alert(data.msg);
                    }
                }
            });
        },'question');
    }
    function xq(id){
        BUI.Message.Confirm("确定续签该区域合伙人吗？",function(){
            $.ajax({
                url :"/member/xq",
                type : 'post',
                data : {id:id},
                success : function(data){
                    BUI.Message.Alert(data.msg);
                }
            });
        },'question');
    }



    var Overlay = BUI.Overlay
    var dialog = new Overlay.Dialog({
        title:'会员统计',
        width:400,
        height:250,
        contentId:'content',
        success:function () {

            dialog.hide();
        }
    });

    function showCnt(id){
        $("#objId").val(id);
        $.ajax({
            url:"/member/memberCnt?ran="+Math.random(),
            type:"post",
            data:{
                id:$("#objId").val()
            },
            success:function(res){
                if(res.success){
                     if(res.data!=null){
                         $("#userTotal").html(res.data.userTotal);
                         $("#userCnt").html(res.data.userCnt);
                         $("#goldCnt").html(res.data.goldCnt);
                         $("#generalCnt").html(res.data.generalCnt);
                         $("#partnerCnt").html(res.data.partnerCnt);
                     }
                    dialog.show();
                    $("#basicId").val("");
                }
            },
            error:function(){}
        });
    }
</script>

<script type="text/javascript" src="/views/js/list.js"></script>
<div id="content"  style="display:none;">
    <form class="form-horizontal">
        <div class="row">
            <input type="hidden" id="objId" name="objId"/>
            <div class="control-group span20">
                <label class="control-label">会员总数：</label>
                <div class="controls" id="userTotal">
                    0
                </div>
            </div>
        </div>
        <div class="row">
            <div class="control-group span20">
                <label class="control-label">普通会员：</label>
                <div class="controls" id="userCnt">
                    0
                </div>
            </div>
        </div>
        <div class="row">
            <div class="control-group span20">
                <label class="control-label">金牌代理：</label>
                <div class="controls" id="goldCnt">
                    0
                </div>
            </div>
        </div>
        <div class="row">
            <div class="control-group span20">
                <label class="control-label">全国总代：</label>
                <div class="controls" id="generalCnt">
                    0
                </div>
            </div>
        </div>
        <div class="row">
            <div class="control-group span20">
                <label class="control-label">区域合伙人：</label>
                <div class="controls" id="partnerCnt">
                    0
                </div>
            </div>
        </div>
    </form>
</div>

</body>
</html>  
